// house_pkg/pages/locate/index.ts
import qqMap from "../../../utils/qqMap"
Page({
  goBuilding(ev) {
    // console.log(ev);
    wx.navigateTo({
      url: '/house_pkg/pages/building/index?point=' + ev.mark.point
    })
  },
  onLoad() {
    // 用户所在位置经纬度
    this.getLocation()
  },
  async getLocation() {
    const { latitude, longitude } = await wx.getLocation()
    console.log(latitude, longitude)
    this.getPoint(latitude, longitude)

  },
  async chooseLocation() {
    const { latitude, longitude } = await wx.chooseLocation()
    console.log(latitude, longitude)
    this.getPoint(latitude, longitude)
  },
  // 根据经纬度获取位置的信息
  getPoint(latitude, longitude) {
    qqMap.reverseGeocoder({
      location: [latitude, longitude].join(','),
      success: ({ result: { address } }) => {
        this.setData({ address })
      }

    })
    qqMap.search({
      keyword: '小区',
      location: [latitude, longitude].join(','),
      page_size: 5,
      success: (res) => {
        console.log(res);
        this.setData({
          points: res.data
        })
      },
    })
  }

})